﻿@model Shop.Page.Models.WaresPicture
@{
    Layout = null;
}

<!DOCTYPE html>

<html>
<head>
    <meta name="viewport" content="width=device-width" />
    <title>UpdatePage</title>
    <style type="text/css">
        #main {
            width: 1000px;
            margin: 50px auto;
        }
    </style>
    <link href="~/Content/BootStrap/css/bootstrap.min.css" rel="stylesheet" />
    <link href="~/Content/BootStrap/css/bootstrap-theme.min.css" rel="stylesheet" />
    <link href="~/Content/BootStrap/css/docs.min.css" rel="stylesheet" />
    <link href="~/bootstrapvalidator-master/dist/css/bootstrapValidator.min.css" rel="stylesheet" />

    <script src="~/Scripts/jquery-1.10.2.min.js"></script>
    <script src="~/Content/BootStrap/js/bootstrap.min.js"></script>
    <script src="~/Content/BootStrap/js/docs.min.js"></script>
    <script src="~/bootstrapvalidator-master/dist/js/bootstrapValidator.min.js"></script>
    <script src="~/bootstrapvalidator-master/dist/js/language/zh_CN.js"></script>


    @*上传*@
    <script src="~/bootstrap-fileinput-master/js/fileinput.min.js"></script>
    <script src="~/bootstrap-fileinput-master/js/locales/zh.js"></script>
    <link href="~/bootstrap-fileinput-master/css/fileinput.min.css" rel="stylesheet" />
</head>
<body>
    <div id="main">
        <form id="UpdateForm" method="post" class="form-horizontal" action="UpdatePage" enctype="multipart/form-data">
            <input type="text" value="@Model.Type" hidden="hidden"/>
            <input type="text" hidden="hidden" value="@Model.Url" name="OldUrl" id="OldUrl" />
            <input type="tel" hidden="hidden" value="@Model.HID" name="HID" id="HID" />
            <div class="form-group">
                <label class="col-lg-2 control-label" for="WID">关联商品ID</label>
                <div class="col-lg-4">
                    <input type="text" class="form-control" id="WID" name="WID" placeholder="关联商品ID" value="@Model.WID">
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label" for="WName">商品名</label>
                <div class="col-lg-8">
                    <input type="text" class="form-control" name="WName" id="WName" placeholder="商品名" readonly="readonly" value="@Model.WName"/>
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label" for="Url">原图片</label>
                <div class="col-lg-4">
                    <img src="@Model.Url" alt="商品图片" class="img-rounded" style="max-width:100px;max-height:100px;">
                </div>
            </div>
            <div class="form-group">
                <label class="col-lg-2 control-label" for="Url">显示图片</label>
                <div class="col-lg-4">
                    <input id="Url" name="Url" type="file" class="file-loading" multiple data-show-caption="true">
                </div>
            </div>
            <div class="form-group">
                <div class="col-lg-2"></div>
                <div class="col-lg-4">
                    <input type="submit" class="btn btn-primary" value="修改" />
                </div>
                <div class="col-lg-4">
                    <input type="button" class="btn btn-primary" id="resetBtn" value="重置" />
                </div>
            </div>
        </form>
    </div>
    <script type="text/javascript">
        $(document).on('ready', function () {
            $("#Url").fileinput({
                language: 'zh', //设置语言
                uploadUrl: "", //上传的地址
                allowedFileExtensions: ['jpg', 'png', 'gif'],//接收的文件后缀
                showUpload: false, //是否显示上传按钮
                showCaption: false,//是否显示标题
                browseClass: "btn btn-primary", //按钮样式
                previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
                maxFileSize: 2000,
            });
        });
        $('#UpdateForm')
            .bootstrapValidator({
                message: 'This value is not valid',
                feedbackIcons: {
                    valid: 'glyphicon glyphicon-ok',
                    invalid: 'glyphicon glyphicon-remove',
                    validating: 'glyphicon glyphicon-refresh'
                },
                fields: {
                    WID: {
                        validators: {
                            notEmpty: {
                                message: '商品ID不能为空'
                            },
                            regexp: {
                                regexp: /(^[1-9]([0-9]+)?$)/,
                                message: 'ID只能是数字'
                            },
                            callback: {
                                message: '不存在该ID的商品或已下架',
                                callback: function (value, validator) {
                                    var res = true;
                                    $.ajax({
                                        url: '@Url.Action("JudgeWares", "Page")',
                                        type: 'post',
                                        dataType: 'text',
                                        async: false,
                                        data: { WID: value },
                                        success: function (data) {
                                            if (data == 'NO') {
                                                res = false;
                                                $("#WName").val(" ");
                                            }
                                            else {
                                                res = true;
                                                $("#WName").val(data);
                                            }
                                        }
                                    });
                                    return res;
                                }
                            }
                        }
                    }
                }
            });
        //重置
        $('#resetBtn').click(function () {
            $('#UpdateForm').data('bootstrapValidator').resetForm(true);
            $('#UpdateForm')[0].reset();
            $("#CID").val("0");
            $("#SCID").empty();
        });
    </script>
</body>
</html>
